import unittest
import os.path
from pybs import database
from pybs import collection
from pysqlite2 import dbapi2 as sqlite
from . import data_file



class DbBasedTestCase(unittest.TestCase):
    
    def setUp(self, init_db_file):
        """
        Initialize database
        
        @param init_db_file: path to the init data file, relative to "data" directory
        """
        self.__default_db_path = ":memory:"
        
        database.import_sql_file(data_file(init_db_file), db_path=self.__default_db_path)
        self.db = database.get_connection(self.__default_db_path)
        self.cursor = self.db.cursor()
        self.db.commit()

    def tearDown(self):
        database.close_connection(self.__default_db_path)
